package de.unibi.comet.ac;

import java.util.Iterator;
import de.unibi.comet.ac.SuffixStructure;
import de.unibi.comet.ac.SuffixStructureNode;

public class SuffixStructureUtils {
	
	static private void pstricksSuffixTree(SuffixStructureNode node, StringBuffer buffer) {
		buffer.append(String.format("\\pstree[]{\\Tcircle[name=n%d]{%d}}{", node.getNumber(), node.getNumber()));
		Iterator<SuffixStructureNode> iter = node.childrenIterator();
		while (iter.hasNext()){
			SuffixStructureNode child = iter.next();
			StringBuffer child_str = new StringBuffer();
			pstricksSuffixTree(child, child_str);
			int k = child_str.indexOf("\\Tcircle");
			if (k>=0) k=child_str.indexOf("}",k);
			if (k>=0){
				buffer.append(child_str.substring(0, k+1));
				buffer.append("\\tlput{"+child.getEdgeText()+"}");
				buffer.append(child_str.substring(k+1));
			}
		}
		buffer.append('}');
	}
	
	static public String pstricksSuffixTree(SuffixStructure ss) {
		StringBuffer buffer = new StringBuffer();
		pstricksSuffixTree(ss.getRoot(), buffer);
		return buffer.toString();
	}
}
